﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ReflexTérkép.Tests.dto;

namespace ReflexTérkép.Tests
{
    [TestClass]
    public class MapDynamicTests : TestBase
    {
        [TestMethod]
        public void Can_Handle_Mapping_A_Single_Dynamic_Object()
        {
            // Arrange
            dynamic dynamicCustomer = new ExpandoObject();
            dynamicCustomer.CustomerId = 1;
            dynamicCustomer.FirstName = "Bob";
            dynamicCustomer.LastName = "Smith";
            dynamicCustomer.Orders_OrderId = 1;
            dynamicCustomer.Orders_OrderTotal = 50.50m;

            // Act
            var customer = ReflexMapper.MapDynamic<Customer>(dynamicCustomer) as Customer;

            // Assert
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.Orders.Count == 1);
        }

        [TestMethod]
        public void Can_Handle_Mapping_Nested_Members_Using_Dynamic()
        {
            // Arrange
            var dynamicCustomers = new List<object>();

            for (int i = 0; i < 5; i++)
            {
                dynamic customer = new ExpandoObject();
                customer.CustomerId = i;
                customer.FirstName = "FirstName" + i;
                customer.LastName = "LastName" + i;
                customer.Orders_OrderId = i;
                customer.Orders_OrderTotal = i + 0m;

                dynamicCustomers.Add(customer);
            }

            // Act
            var customers = ReflexMapper.MapDynamic<Customer>(dynamicCustomers);

            // Assert
            Assert.IsTrue(customers.Count() == 5);
            Assert.IsTrue(customers.First().Orders.Count == 1);

        }
    }
}
